// pages/index/shopInfo.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    data: {},
    loading: 0,
    disabled: 0,
    order_sn: "",
    userInfo: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var type = options.type;
    app.getUserInfo((info) => {
      this.setData({ userInfo:info});
      this.getPartner();
    })
    

  },
  getPartner() {
    var that = this;
    app.api("apiv2/member_partner/find", function (res) {
      var showOpenPartner = 0;
      if (res.data && res.data.status == 0) {
        showOpenPartner = 1;
      }
      that.setData({ showOpenPartner: showOpenPartner, data:res.data })
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  formSubmit: function (e) {
   
    //手机号登陆
    var that = this;
    that.setData({
      loading: 1,
      disabled: 1
    });
    that.data.order_sn = that.data.data.order_sn;
    that.pay();
  },

  pay: function () {
    var that = this;
    var order_sn = this.data.order_sn;
    app.api("apiv2/pay/run", { order_sn: order_sn, getJson: 1, paytype: "pay.weixin.jspay", openid: that.data.userInfo.openid }, function (res) {
      if (res.code != 200) {
        app.alert(res.msg);
        that.setData({
          loading: 0,
          disabled: 0
        });
        return;
      }
      var PayInfo = JSON.parse(res.data.PayInfo);
      PayInfo.success = function (res) {
        that.setData({
          loading: 0,
          disabled: 0
        });
        app.setPageData("user/index", { reload: 1 });
        wx.navigateBack();
      };
      PayInfo.fail = function (res) {
        that.setData({
          loading: 0,
          disabled: 0
        });
      };

      wx.requestPayment(PayInfo);
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getShopInfo();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})